package com.appsky.drift.adapter;

import com.appsky.drift.R;
import com.appsky.drift.api.DLog;
import com.appsky.drift.api.UserInfo;

import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class RoomPersonListItem extends RelativeLayout {

	private static final int FEMALE_SEX = 0;

	private static final int MALE_SEX = 1;

	private static final int SECRECY_SEX = 2;

	private Context context;

	private TextView personNick;

	private ImageView sexIcon;

	private TextView stateText;

	public RoomPersonListItem(Context context) {
		super(context);
		this.context = context;
		initView();
	}

	public void show(UserInfo item) {
		personNick.setText(item.getNick());
		setSexIcon(item);
		setStateIcon(item);
	}

	private void initView() {
		RelativeLayout view = (RelativeLayout) View.inflate(context,
				R.layout.room_person_list_item, null);
		personNick = (TextView) view.findViewById(R.id.nick_text);
		sexIcon = (ImageView) view.findViewById(R.id.sex_image);
		stateText = (TextView) view.findViewById(R.id.state_text);
		addView(view);
	}

	private void setSexIcon(UserInfo item) {
		switch (item.getSex()) {
		case FEMALE_SEX:
			sexIcon.setImageResource(R.drawable.female);
			break;
		case MALE_SEX:
			sexIcon.setImageResource(R.drawable.male);
			break;
		case SECRECY_SEX:
			sexIcon.setImageResource(R.drawable.secrecy);
			break;

		}
	}

	private void setStateIcon(UserInfo item) {
		if (item.isRoomOwner()) {
			stateText.setVisibility(View.VISIBLE);
			stateText.setText("主");
			stateText.setTextColor(Color.RED);
		} else {
			stateText.setVisibility(View.INVISIBLE);
		}
	}
}
